package com.mediacloud.app.newsmodule.fragment.drama;

import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.ArticleListData;
import com.mediacloud.app.model.news.BaseMessageReciver;
import com.mediacloud.app.model.news.kt.TypeX;
import com.mediacloud.app.newsmodule.adaptor.NewsListItemStyleAdaptor;
import com.mediacloud.app.newsmodule.adaptor.bigimg_nosliceline.BigImageNoSliceLineAdaptor;
import com.mediacloud.app.newsmodule.adaptor.drama.DramaListItemStyleAdaptor;
import com.mediacloud.app.newsmodule.fragment.newslist.NewsListWidthBannerFragment;
import com.mediacloud.app.reslib.enums.StyleOther;


public class DramaListFregment extends NewsListWidthBannerFragment {
	public DramaListFregment() {
	}
	@Override
	public void initView() {
		super.initView();
		//父类可能初始化了adapter，就会在adapter中注册eventbus，需要反注册
		if (adaptor instanceof NewsListItemStyleAdaptor){
			((NewsListItemStyleAdaptor) adaptor).destroy();
		}
		if (adaptor instanceof BigImageNoSliceLineAdaptor){
			((BigImageNoSliceLineAdaptor) adaptor).destroy();
		}
		//如果有其他样式的 就用这个列表样式了
		if(catalogItem.getCatalogStyle()== StyleOther.OtherStyle)//&&catalogItem.getStyleOther()!=null)
		{
			adaptor=new BigImageNoSliceLineAdaptor(getActivity(),catalogItem,playClickListener);
		}else{
			adaptor=new DramaListItemStyleAdaptor(getActivity(), catalogItem);
		}
		mCatalogContentItemListView.setAdapter(adaptor);
	}

	@Override
	protected void addBanner()
	{
		int extraStyle=catalogItem!=null?catalogItem.getCatalogStyle():0;
		if(extraStyle>0){
			haveBanner=false;
		}
		else
			super.addBanner();

	}
	@Override
	protected Class<? extends BaseDataInvokeCallBack<? extends BaseMessageReciver>> getDataInvokeCallBackClass()
	{
		return DramaListCallBack.class;
	}

	public class DramaListCallBack extends NewsListDataInvokeCallBack
	{
		@Override
		public void success(ArticleListData result) {
			if (getActivity() == null || requireActivity().isFinishing()||requireActivity().isDestroyed()) {
				return ;
			}
			if(result.articleList!=null)
			{
				for(ArticleItem articleItem:result.articleList)
				{
					articleItem.setType(TypeX.NEWS.DRAMA);
				}
			}
			super.success(result);
		}
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		if (adaptor instanceof DramaListItemStyleAdaptor){
			((DramaListItemStyleAdaptor) adaptor).clearEvent();
			((DramaListItemStyleAdaptor) adaptor).clearSpiderObservers();
		}
	}
}